package org.xdq.demo;
//springboot应用的启动类，应用的运行就从这个类的主方法开发

import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.nio.charset.StandardCharsets;
import java.util.List;

//如下注解可以实现自动扫描本类所在的包及其子包下的组件
@SpringBootApplication//该注解说明本类是springboot应用的启动类，该注解包含如下注解的作用：@Configuration @EnableAutoConfiguration @ComponentScan
@MapperScan("org.xdq.demo.dao")
public class App {

    public static void main(String[] args) {
        SpringApplication.run(App.class,args);
    }

    @Bean
    public WebMvcConfigurer webMvcConfigurer(){
        return new WebMvcConfigurer() {
            @Override
            public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
                StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
                stringHttpMessageConverter.setDefaultCharset(StandardCharsets.UTF_8);
                converters.add(0,stringHttpMessageConverter);

                FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter();
                fastJsonHttpMessageConverter.setDefaultCharset(StandardCharsets.UTF_8);
                converters.add(1,fastJsonHttpMessageConverter);
            }

            @Override
            public void addViewControllers(ViewControllerRegistry registry) {
                registry.addRedirectViewController("/","/index.html");
            }


        };
    }

}
